<template>
	<view class="content">
		<scroll-view style="height: calc(100vh);" scroll-y="true" class="scroll-Y" @scrolltolower="lower">
			<view v-if="list.length == 0" class="wid100 dis disAl disJuC" style="height: 80%;">
				<image src="../../static/incomeDetail/wushiju.png" style="width: 197rpx;height: 226rpx;"></image>
			</view>
			<view v-else style="height: 1rpx;"></view>
			<view v-if="list.length != 0" v-for="(item,index) in list" :key="index" 
				class="wid90 mar mar-top30 bacFFF borRad20">
				<view class="wid90 mar" style="padding: 20rpx 0;">
					<view class="foSi40">{{item.name}}<span v-if="item.check_status == 0" style="color: #1262DB;">(审核中)</span><span v-if="item.check_status == 1" style="color: green;">(已通过)</span><span v-if="item.check_status == 2" style="color: red;">(已驳回)</span></view>
					<view class="dis disAl disJuB hei60 foSi25" style="color: #AEACAC;">
						<view>成员姓名：{{item.uid_text}}</view>
						<view>负责人：{{item.user}}</view>
					</view>
					<view class="dis disAl foSi25">
						<view style="width: 65%;color: #AEACAC;">
							<view>创建时间：{{item.createtime}}</view>
							<view class="mar-top20">负责人电话：{{item.user_phone}}</view>
						</view>
						<view class="dis disAl coFFF" style="width: 35%;">
							<view @click="tz(item)"
							class="dis disAl disJuC borRad10 mar-right20" style="width: 98rpx;height: 55rpx;background-color: #1262DB">修改</view>
							<view @click="shanchu(index)"
							class="dis disAl disJuC borRad10" style="width: 98rpx;height: 55rpx;background-color: #ff0000">删除</view>
						</view>
					</view>
					<view class="foSi25 mar-top20 dis disAl disJuB" style="color: #AEACAC;">
						<view class="dis disAl">
							<image src="../../static/myGroup/weizhi.png" style="width: 24rpx;height: 32rpx;"></image>
							<view class="mar-left10" style="max-width: 350rpx;">{{item.province+'-'+item.city+'-'+item.area+' '+item.address}}</view>
						</view>
						<view class="dis disAl disJuC borRad10"  style="width: 140rpx;height: 55rpx;background-color: #1262DB;color:#fff" @click="tiaozhuan('/pages/clinic/reagent_list?clinic_id='+item.id)">
							试剂管理
						</view>
					</view>
				</view>
			</view>
			<view style="height: 100rpx;"></view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: this.global.url,
				last_page: 0,
				page: 0,
				list: []
			}
		},
		onLoad() {
		},
		onShow(){
			this.page = 0
			this.getList()
		},
		methods: {
			tz(item){
				// '/pages/clinic/add?list='+encodeURIComponent(JSON.stringify(item))
				uni.setStorageSync('clinicdetail',item)
				uni.navigateTo({
					url: '/pages/clinic/add'
				});
			},
			tiaozhuan(url){
				uni.navigateTo({
					url: url
				});
			},
			lower: function(e) {
				if(this.last_page != this.page+1){
					this.page++
					this.getList()
				}
			},
			shanchu(index){
				var that = this
				// 给个提示框
				uni.showModal({
						title: '提示',
						// 提示文字
						content: '确认删除该诊所吗？',
						// 取消按钮的文字自定义
						cancelText: "取消",
						// 确认按钮的文字自定义
						confirmText: "删除",
						//删除字体的颜色
						confirmColor:'red',
						//取消字体的颜色
						cancelColor:'#000000',
						success: function(res) {
						if (res.confirm) {
							// 执行确认后的操作
							uni.request({
							    url: that.global.url + 'api/clinic/del',
							    method: "POST",
								header: {
									'token': uni.getStorageSync('token')
								},
							    data: {
									id: that.list[index].id
								},
							    success(res) {
							        let result = res.data
							        if(result.code == 1){
										that.list.splice(index,1)
									}else{
							           uni.showToast({
							           	title: result.msg,
							           	icon: 'error'
							           })
							        }
							       
							    }
							})
						} 
						else {
							// 执行取消后的操作
						}
					}
				})
				
			},
			getList(){
				var that = this
				uni.request({
				    url: that.global.url + 'api/clinic/index',
				    method: "POST",
					header: {
						'token': uni.getStorageSync('token')
					},
				    data: {
						type: 1,
						page: this.page
					},
				    success(res) {
				        let result = res.data
				        if(result.code == 1){
							that.last_page = result.data.last_page
							if(that.page == 0){
								that.list = result.data.data
							}else{
								that.list = that.list.concat(result.data.data)
							}
						}else{
				           uni.showToast({
				           	title: result.msg,
				           	icon: 'error'
				           })
				        }
				       
				    }
				})
			},
		}
	}
</script>

<style>
	.content {
		height: 100vh;
		background-color: #F0F0F0;
	}
	::-webkit-scrollbar {
		display: none;
	}
</style>
